package com.ls.lsqc.modules.sys.entity;

import java.util.List;

import com.google.common.collect.Lists;
import com.ls.lsqc.common.persistence.DataEntity;
import com.ls.lsqc.common.utils.StringUtils;

/**
 * 角色Entity
 * @author 
 * @version 2013-12-05
 */
public class Role extends DataEntity<Role> {
	
	private static final long serialVersionUID = 1L;
	
	private String oldName;    // 原角色名称
	
	private String sysData;        //是否是系统数据
	
	private User user;		// 根据用户ID查询角色列表

//	private List<User> userList = Lists.newArrayList(); // 拥有用户列表
	private List<Menu> menuList = Lists.newArrayList(); // 拥有菜单列表

	// 数据范围（1：所有数据；2：所在公司及以下数据；3：所在公司数据；4：所在部门及以下数据；5：所在部门数据；8：仅本人数据；9：按明细设置）
	/*public static final String DATA_SCOPE_ALL = "1";
	public static final String DATA_SCOPE_COMPANY_AND_CHILD = "2";
	public static final String DATA_SCOPE_COMPANY = "3";
	public static final String DATA_SCOPE_OFFICE_AND_CHILD = "4";
	public static final String DATA_SCOPE_OFFICE = "5";
	public static final String DATA_SCOPE_SELF = "8";
	public static final String DATA_SCOPE_CUSTOM = "9";*/
	
	public Role() {
		super();
		/*this.dataScope = DATA_SCOPE_SELF;
		this.useable=Global.YES;*/
	}
	
	public Role(Long id){
		super(id);
	}
	
	public Role(User user) {
		this();
		this.user = user;
	}

    public List<Menu> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<Menu> menuList) {
		this.menuList = menuList;
	}

	public List<Long> getMenuIdList() {
		List<Long> menuIdList = Lists.newArrayList();
		for (Menu menu : menuList) {
			menuIdList.add(menu.getId());
		}
		return menuIdList;
	}

	public void setMenuIdList(List<String> menuIdList) {
		menuList = Lists.newArrayList();
		for (String menuId : menuIdList) {
			Menu menu = new Menu();
			menu.setId(Long.parseLong(menuId));
			menuList.add(menu);
		}
	}

	public String getMenuIds() {
		return StringUtils.join(getMenuIdList(), ",");
	}
	
	public void setMenuIds(String menuIds) {
		menuList = Lists.newArrayList();
		if (menuIds != null){
			String[] ids = StringUtils.split(menuIds, ",");
			setMenuIdList(Lists.newArrayList(ids));
		}
	}
	

	/**
	 * 获取权限字符串列表
	 */
	public List<String> getPermissions() {
		List<String> permissions = Lists.newArrayList();
		for (Menu menu : menuList) {
			if (menu.getMenuPermission()!=null && !"".equals(menu.getMenuPermission())){
				permissions.add(menu.getMenuPermission());
			}
		}
		return permissions;
	}
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

    public String getOldName() {
        return oldName;
    }

    public void setOldName(String oldName) {
        this.oldName = oldName;
    }

    public String getSysData() {
        return sysData;
    }

    public void setSysData(String sysData) {
        this.sysData = sysData;
    }

	// 角色名称
	private String    roleName;
	
	// 角色描述
	private String    roleDescription;
	
	// 角色类型  1、平台角色；2、店铺角色；3、加工厂角色
	private Long      roleType;
	
	// 是否系统数据（0、否；1、是）默认0、否
	private Long      roleSys;
	
	// 数据范围（1、所有数据；2、所在公司数据；3、所在公司以下数据；4、所在部门及数据；5、所在部门及以下数据；6、仅本人数据）
	private Long      roleScope;
	
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	public String getRoleDescription() {
		return roleDescription;
	}
	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}
	public Long getRoleType() {
		return roleType;
	}
	public void setRoleType(Long roleType) {
		this.roleType = roleType;
	}
	public Long getRoleSys() {
		return roleSys;
	}
	public void setRoleSys(Long roleSys) {
		this.roleSys = roleSys;
	}
	public Long getRoleScope() {
		return roleScope;
	}
	public void setRoleScope(Long roleScope) {
		this.roleScope = roleScope;
	}
	
}
